﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class DrawLineRender : MonoBehaviour {
	public Color materialColor;
	LineRenderer lineRenderer_global;
	Vector3 startPos;
	Vector3 endPos;
	Vector3[] poss;
	[SerializeField]
	private Vector3 offset=Vector3.zero;
	[SerializeField]
	[Range(0f,0.2f)]
	private float width=0.1f;
	void Awake () {

		LineRenderer lineRenderer = this.gameObject.AddComponent<LineRenderer> ();
		Material material=new Material(Shader.Find("Unlit/Color"));
		lineRenderer.material = material;
		lineRenderer.material.color = materialColor;
		lineRenderer.widthMultiplier = width;
		lineRenderer.positionCount = 2;
		lineRenderer.numCornerVertices=30;
		lineRenderer.numCapVertices=30;

		startPos = this.transform.parent.GetChild (2).transform.localPosition;
		endPos = this.transform.parent.GetChild (0).transform.localPosition;
		//var offset=new Vector3(0,1.254f,0);
		poss = new Vector3[2] { startPos-offset, endPos-offset };		
	}
	void Start()
	{
		lineRenderer_global= this.GetComponent<LineRenderer> ();
	}
	void Update () {

		for (int i = 0; i < lineRenderer_global.positionCount; i++) {
			lineRenderer_global.SetPosition (i, poss[i]);
		}
	}
}